var mysql = require("mysql");

var pool = mysql.createPool({
    host: '47.107.243.60',
    user: 'Flechazo',
    password: 'MySQL5.7',
    database: 'user',
    port: 3306
});

//callback为回调方法
async function queryDataBySQL(sql, callback) {
    return await new Promise((reslove,reject)=>{
        pool.getConnection(function (err, connection) {
          connection.query(sql, function (err, result) {
              if (err) { reject(err) } else {
                if(callback){
                  callback(result)
                }
                reslove(1)
              }
  
          });
          connection.release();
          //console.log("close mysql connection");
        });
    })
};

module.exports = {
    queryDataBySQL
}